<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>1.画图形</title>
</head>
<body>
	<canvas id="canvas"></canvas>
	<script type="x-shader/x-vertex" id="vertex">
		attribute vec4 a_position;
		void main(){
			gl_Position = a_position;
		}
	</script>
	<script type="x-shader/x-fragment" id="fragment">
		void main(){
			gl_FragColor = vec4(1.0,0.0,1.0,1.0);
		}
	</script>
	<script src="https://webglfundamentals.org/webgl/resources/webgl-utils.js"></script>
	<script src="https://webglfundamentals.org/webgl/resources/m4.js"></script>
	<script src="https://webglfundamentals.org/webgl/resources/primitives.js"></script>
	<script src="https://webglfundamentals.org/webgl/resources/texture-utils.js"></script>
	<script src="https://webglfundamentals.org/webgl/resources/chroma.min.js"></script>
	<script>
		/** @type {HTMLCanvasElement} */   
		const canvas=document.getElementById("canvas")
		const gl=canvas.getContext("webgl")
		const programInfo=webglUtils.createProgramInfo(gl,["vertex","fragment"])
		gl.useProgram(programInfo.program)
		const a_position=gl.getAttribLocation(programInfo.program,"a_position")
		const buffer=gl.createBuffer()
		const positions=[
			-.8,  .8, 0, 1,  // 1st rect 1st triangle
			.8,  .8, 0, 1,
			-.8,  .2, 0, 1,
			
			-.8,  .2, 0, 1,  // 1st rect 2nd triangle
			.8,  .8, 0, 1,
			.8,  .2, 0, 1,
		]
		
		gl.enableVertexAttribArray(a_position)
		
		gl.bindBuffer(gl.ARRAY_BUFFER,buffer)
  		gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);
		gl.vertexAttribPointer(a_position,4,gl.FLOAT,false,0,0)

		gl.drawArrays(gl.TRIANGLES,0,6)
	</script>
</body>
</html>